<template>
<div class="am-swiper-container" :class="'am-swiper-container-'+direction" :style="containerStyle">
  <slot name="before"></slot>
  <div
    class="am-swiper-wrapper am-swiper-wrapper-slide"
    ref="wrapper"
    @transitionEnd="onTransitionEnd"
    @webkitTransitionEnd="onTransitionEnd"
  >
    <slot></slot>
  </div>
  <slot name="after"></slot>
</div>
</template>
<style>.am-swiper-container{overflow:hidden}.am-swiper-container-horizontal .am-swiper-wrapper{-webkit-box-orient:horizontal;-webkit-box-direction:normal;-webkit-flex-direction:row;flex-direction:row}.am-swiper-container-vertical .am-swiper-wrapper{-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;flex-direction:column}.am-swiper-wrapper{display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-box-pack:start;-webkit-justify-content:flex-start;justify-content:flex-start;-webkit-box-align:center;-webkit-align-items:center;align-items:center;position:relative}.am-swiper-wrapper-slide{-webkit-transition:-webkit-transform linear 0s;transition:-webkit-transform linear 0s;transition:transform linear 0s;transition:transform linear 0s, -webkit-transform linear 0s}</style>
<script type="text/javascript" generated>'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _gesture=require('./gesture');var _gesture2=_interopRequireDefault(_gesture);var _utils=require('./utils');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}exports.default={name:'Swiper',props:{dirDegree:{type:Number,default:20},direction:{type:String,default:'horizontal'},freeMode:{type:Boolean,default:true},height:[Number,String],resistant:{type:Number,default:0.2},reverseTime:{type:Number,default:0.15},reverseTimingFunction:{type:String,default:'linear'},slideTime:{type:Number,default:0.3},slideTimingFunction:{type:String,default:'ease-out'},slideRate:{type:Number,default:0.1},detectChildren:{type:Boolean,default:false}},data:function data(){return{offset:0,distance:0,transition:'none',moving:false,reverse:false,moveDisabled:false,moveCount:0,childCreatedTag:0}},computed:{childrenWidth:function childrenWidth(){this.childCreatedTag;return this.$children.map(function(a){if(a.width){return parseInt(a.width)}if(process.env.NODE_ENV!=='production'){console.warn('[Warn] The width of BaseSwiperItem should be set.')}var b=window.getComputedStyle(a.$el||a);var c=parseInt(b.width)+parseInt(b.marginLeft)+parseInt(b.marginRight);if(b.boxSizing==='content-box'){c+=parseInt(b.paddingLeft)+parseInt(b.paddingRight)}return c})},childrenHeight:function childrenHeight(){this.childCreatedTag;return this.$children.map(function(a){if(a.height){return parseInt(a.height)}if(process.env.NODE_ENV!=='production'){console.warn('[Warn] The height of BaseSwiperItem should be set.')}var b=window.getComputedStyle(a.$el||a);var c=parseInt(b.height)+parseInt(b.marginTop)+parseInt(b.marginBottom);if(b.boxSizing==='content-box'){c+=parseInt(b.paddingTop)+parseInt(b.paddingBottom)}return c})},childrenOffset:function childrenOffset(){var a=void 0;if(this.direction==='horizontal'){a=this.childrenWidth}else{a=this.childrenHeight}var b=[];var c=0;a.forEach(function(a){b.push(c);c-=a});return b},childrenReverseOffset:function childrenReverseOffset(){var a=void 0;if(this.direction==='horizontal'){a=this.childrenWidth}else{a=this.childrenHeight}var b=[];var c=this.minOffset;for(var d=a.length-1;d>=0;d--){b.unshift(c);c+=a[d]}return b},heightMeta:function heightMeta(){return(0,_utils.transformValueUnit)(this.height)},heightUnit:function heightUnit(){var a=this.heightMeta;if(a.value){return''+a.value+a.unit}},containerStyle:function containerStyle(){var a=this.heightUnit||this.height;if(a){return{height:a}}}},mounted:function mounted(){if(this.direction==='vertical'&&typeof this.height==='undefined'){console.error('Height should be specificed when direction is "vertical"');return}var a=new _gesture2.default(this.$el);a.on('touchstart',this.onStart);a.on('move',this.onMove);a.on('touchfinish',this.onFinish);this.gesture=a;var b=window.getComputedStyle(this.$el);if(this.direction==='horizontal'){this.minOffset=parseInt(b.width)-this.$refs.wrapper.scrollWidth}else{this.minOffset=parseInt(b.height)-this.$refs.wrapper.scrollHeight}},updated:function updated(){var a=window.getComputedStyle(this.$el);if(this.direction==='horizontal'){this.minOffset=parseInt(a.width)-this.$refs.wrapper.scrollWidth}else{this.minOffset=parseInt(a.height)-this.$refs.wrapper.scrollHeight}},created:function created(){this.$on('child-created',this.onChildCreated)},beforeDestroy:function beforeDestroy(){this.gesture.dispose()},methods:{onChildCreated:function onChildCreated(){if(this.detectChildren){this.childCreatedTag++;this.childCreatedTag%=1e9}},onStart:function onStart(){this.moveDisabled=false;this.moveCount=0},calculateDistance:function calculateDistance(a){return a*this.resistant},onMove:function onMove(a,b){var c=b.direction,d=b.distance,e=b.speed,f=b.dirDegree;this.moveCount++;if(this.moveDisabled){return}if(this.minOffset>=0){return}this.moving=true;this.reverse=false;if((c!==this.direction||this.dirDegree<Math.abs(f))&&this.moveCount<=1){this.moveDisabled=true;return}a.preventDefault();var g=this.offset+d;if(g<0&&g>this.minOffset){this.distance=d}else if(g>0){this.distance=this.calculateDistance(g)-this.offset}else if(g<this.minOffset){this.distance=this.calculateDistance(g-this.minOffset)+this.minOffset-this.offset}this.updateTransition();this.updateTransform()},onFinish:function onFinish(a,b){var c=b.speed;if(this.moveDisabled){return}if(this.minOffset>=0){return}this.moving=false;this.offset+=this.distance||0;if(this.offset<this.minOffset){this.offset=this.minOffset;this.reverse=true}if(this.offset>0){this.offset=0;this.reverse=true}if(!this.reverse&&this.offset<=0&&this.offset>=this.minOffset){var f=c*this.slideRate;this.offset+=f;if(this.offset<this.minOffset){this.offset=this.minOffset}if(this.offset>0){this.offset=0}}var d=0;var e=34359738367;for(var g=0;g<this.childrenOffset.length;g++){if(Math.abs(this.offset-this.childrenOffset[g])<e){e=Math.abs(this.offset-this.childrenOffset[g]);d=g}}if(!this.freeMode){this.offset=this.childrenOffset[d]}this.scrollIndex=d;this.$emit('stop',d);this.distance=0;this.updateTransition();this.$nextTick(this.updateTransform.bind(this))},onTransitionEnd:function onTransitionEnd(a){if(typeof this.scrollIndex==='number'){this.$emit('stopend',this.scrollIndex);this.scrollIndex=null}},updateTransition:function updateTransition(){var a=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;if(this.moving||!a){this._updateTransition(false)}else if(this.reverse){this._updateTransition(true,''+this.reverseTimingFunction,this.reverseTime+'s')}else{this._updateTransition(true,''+this.slideTimingFunction,this.slideTime+'s')}},updateTransform:function updateTransform(){var a=this.direction==='vertical';var b=this.offset+this.distance;var c=a?0:b;var d=a?b:0;this.$refs.wrapper.style.transform=this.$refs.wrapper.style.webkitTransform='translate3d('+c+'px, '+d+'px, 0)'},_updateTransition:function _updateTransition(a,b,c){var d=a?'all '+b+' '+c:'none';this.$refs.wrapper.style.webkitTransition=this.$refs.wrapper.style.transition=d},scrollToIndex:function scrollToIndex(a){var b=this;var c=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'default';var d=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var e=void 0;switch(c){case'reverse':e=this.childrenReverseOffset;break;case'center':e=this.childrenOffset.map(function(a,c){return(a+b.childrenReverseOffset[c])/2});break;default:e=this.childrenOffset;break;}if(this.minOffset>0){return}if(typeof e[a]==='undefined'){return}var f=e[a];f=Math.min(0,f);f=Math.max(this.minOffset,f);this.offset=f;this.distance=0;this.updateTransition(d);this.updateTransform()},scrollTo:function scrollTo(a){var b=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;a=Math.min(0,a);a=Math.max(this.minOffset,a);this.offset=a;this.distance=0;this.updateTransition(b);this.updateTransform()}}};</script>

